package com.ruoyi.garbage.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.excel.ExcelUtils;
import com.ruoyi.garbage.domain.KeywordResult;
import com.ruoyi.garbage.service.IKeywordResultService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 关键词+结果记录Controller
 *
 * @author 刘哲贤
 * @date 2023-01-07
 */
@RestController
@RequestMapping("/admin/keywordResult")
public class KeywordResultController extends BaseController {
    @Resource
    private IKeywordResultService keywordResultService;

    /**
     * 查询关键词+结果记录列表
     */
    @PreAuthorize("@ss.hasPermi('admin:keywordResult:list')")
    @GetMapping("/list")
    public TableDataInfo list(KeywordResult keywordResult) {
        startPage();
        List<KeywordResult> list = keywordResultService.selectKeywordResultList(keywordResult);
        return getDataTable(list);
    }

    /**
     * 导出关键词+结果记录列表
     */
    @PreAuthorize("@ss.hasPermi('admin:keywordResult:export')")
    @Log(title = "关键词+结果记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KeywordResult keywordResult) {
        List<KeywordResult> list = keywordResultService.selectKeywordResultList(keywordResult);
        ExcelUtils<KeywordResult> util = new ExcelUtils<KeywordResult>(KeywordResult.class);
        util.exportData(response, list, "关键词+结果记录数据");
    }

    /**
     * 获取关键词+结果记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('admin:keywordResult:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(keywordResultService.selectKeywordResultById(id));
    }

    /**
     * 新增关键词+结果记录
     */
    @PreAuthorize("@ss.hasPermi('admin:keywordResult:add')")
    @Log(title = "关键词+结果记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KeywordResult keywordResult) {
        return toAjax(keywordResultService.insertKeywordResult(keywordResult));
    }

    /**
     * 修改关键词+结果记录
     */
    @PreAuthorize("@ss.hasPermi('admin:keywordResult:edit')")
    @Log(title = "关键词+结果记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KeywordResult keywordResult) {
        return toAjax(keywordResultService.updateKeywordResult(keywordResult));
    }

    /**
     * 删除关键词+结果记录
     */
    @PreAuthorize("@ss.hasPermi('admin:keywordResult:remove')")
    @Log(title = "关键词+结果记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(keywordResultService.deleteKeywordResultByIds(ids));
    }
}
